package com.xique.client.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xique.client.bean.domain.ParkOn;
import com.xique.client.bean.search.ParkOnSearch;
import com.xique.client.bean.vo.ClientHandOutParkInInfoVo;
import com.xique.client.mapper.ParkOnMapper;
import com.xique.client.service.service.IParkOnService;
import com.xique.common.datascope.annotation.NeedSetDictLabel;
import com.xique.common.datascope.annotation.NeedSetFieldValue;
import com.xique.common.core.text.Convert;
import com.xique.common.core.utils.StringUtils;
import com.xique.common.redis.configure.RedisEvict;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 在场车辆Service业务层处理
 *
 * @author ww
 * @date 2019-10-16
 */
@Service
public class ParkOnServiceImpl implements IParkOnService
{
    @Autowired
    private ParkOnMapper parkOnMapper;

    /**
     * 查询在场车辆
     *
     * @param id 在场车辆ID
     * @return 在场车辆
     */
    @Override
    @NeedSetFieldValue
    public ParkOn selectParkOnById(Long id)
    {
        return parkOnMapper.selectParkOnById(id);
    }

    @Override
    public ParkOn selectParkOn(ParkOnSearch search) {
        QueryWrapper<ParkOn> wrapper = new QueryWrapper<>();
        if (null != search.getId()) {
            wrapper.eq("id", search.getId());
        }
        if (StringUtils.isNotEmpty(search.getParkingSerial())) {
            wrapper.eq("parking_serial", search.getParkingSerial());
        }
        wrapper.orderByDesc("UNIX_TIMESTAMP(update_time)")
                .last("limit 1");

        return parkOnMapper.selectOne(wrapper);
    }

    /**
     * 查询在场车辆列表
     *
     * @param parkOn 在场车辆
     * @return 在场车辆
     */
    @Override
    @NeedSetFieldValue
    @NeedSetDictLabel
    public List<ParkOn> selectParkOnList(ParkOn parkOn)
    {
    	List<ParkOn> list = parkOnMapper.selectParkOnList(parkOn);
    	return list;
    }

    /**
     * 新增在场车辆
     *
     * @param parkOn 在场车辆
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @RedisEvict(field="'*ParkOn*'",type= ParkOn.class)
    public int insertParkOn(ParkOn parkOn)
    {
        return parkOnMapper.insertParkOn(parkOn);
    }

    /**
     * 修改在场车辆
     *
     * @param parkOn 在场车辆
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @RedisEvict(field="'*ParkOn*'",type= ParkOn.class)
    public int updateParkOn(ParkOn parkOn)
    {
        return parkOnMapper.updateParkOn(parkOn);
    }

    /**
     * 删除在场车辆对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @RedisEvict(field="'*ParkOn*'",type= ParkOn.class)
    public int deleteParkOnByIds(String ids)
    {
        return parkOnMapper.deleteParkOnByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除在场车辆信息
     *
     * @param id 在场车辆ID
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @RedisEvict(field="'*ParkOn*'",type= ParkOn.class)
    public int deleteParkOnById(Long id)
    {
        return parkOnMapper.deleteParkOnById(id);
    }

	@Override
	public Long selectParkOnCount(ParkOn parkOn) {
		return parkOnMapper.selectParkOnCount(parkOn);
	}

	@Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @RedisEvict(field="'*ParkOn*'",type= ParkOn.class)
	public int updateChargeId(ParkOn parkOn) {
		// TODO Auto-generated method stub
		return parkOnMapper.updateChargeId(parkOn);
	}

	@Override
	public int deleteParkOnByInId(long id) {
		// TODO Auto-generated method stub
		return parkOnMapper.deleteParkOnByInId(id);
	}

    @Override
    public List<ClientHandOutParkInInfoVo> getHandOutParkInInfoVoList(ParkOn parkOn) {
        return parkOnMapper.getHandOutParkInInfoVoList(parkOn);
    }
}
